package base.utils;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;

public class JumpUtils {
	/**
	 * Jump to activity.
	 */
	public static void jumpTo(Activity fromActivity, Fragment fromFragment, Class<?> to, Bundle bundle) {
		jumpTo(fromActivity, fromFragment, to, bundle, -1);
	}

	/**
	 * Jump to activity.
	 * 
	 * @param fromActivity
	 * @param to
	 */
	public static void jumpTo(Activity fromActivity, Class<?> to) {
		jumpTo(fromActivity, null, to, null, -1);
	}

	/**
	 * Jump to activity.
	 * 
	 * @param fromActivity
	 *            The from-activity.
	 * @param fromFragment
	 *            The from-fragment.
	 * @param to
	 *            The target activity.
	 * @param bundle
	 *            The data.
	 * @param requestCode
	 *            Request Code for ActivityResult.
	 */
	public static void jumpTo(Activity fromActivity, Fragment fromFragment, Class<?> to, Bundle bundle, int requestCode) {
		Intent intent = new Intent(fromFragment == null ? fromActivity : fromFragment.getActivity(), to);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		if (fromFragment != null) {
			if (requestCode > 0) {
				fromFragment.startActivityForResult(intent, requestCode);
			} else {
				fromFragment.startActivity(intent);
			}
		} else {
			if (requestCode > 0) {
				fromActivity.startActivityForResult(intent, requestCode);
			} else {
				fromActivity.startActivity(intent);
			}
		}
	}

}
